//
//  ImageTableViewCell.m
//  网易
//
//  Created by Roach on 16/6/22.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ImageTableViewCell.h"
#import "NewsModel.h"
#import "GatHeightTools.h"
#import "UIImageView+WebCache.h"

@interface ImageTableViewCell ()

@property (nonatomic, retain) UIImageView *newsImageView;

@property (nonatomic, retain) UILabel *imageLabel;

@end

@implementation ImageTableViewCell

- (void)dealloc {
    
    [_newsImageView release];
    [_imageLabel release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.newsImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_newsImageView];
        [_newsImageView release];
        
        self.imageLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_imageLabel];
        [_imageLabel release];
        
    }
    return self;
}
- (void)layoutSubviews{
    
    CGFloat imageHeight = [GatHeightTools imageHeightWith:self.imageModel.img];
    
    self.newsImageView.frame = CGRectMake(0, 20, self.contentView.bounds.size.width, imageHeight);
    self.newsImageView.backgroundColor = [UIColor yellowColor];
    
    self.imageLabel.frame = CGRectMake(imageHeight, 20, self.contentView.bounds.size.width, imageHeight);
    
    _imageLabel.backgroundColor = [UIColor redColor];
}

- (void)setImageModel:(NewsModel *)imageModel {
    
    if (_imageModel != imageModel) {
        [_imageModel release];
        _imageModel = [imageModel retain];
    }
    
    NSURL *url = [NSURL URLWithString:imageModel.img];
    
    [_newsImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"11.jpg"]];
    
    self.imageLabel.text = imageModel.digest;
    
}

@end
